package ru.ng.sample.ui.settings;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.theme.AbstractThemeResolver;
import ru.ng.sample.core.user.ProfileManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: NGorosh
 * Date: 23.05.11
 * Time: 11:54
 */
public class UserProfileThemeResolver
    extends AbstractThemeResolver
{
    @Autowired
    private ProfileManager profileManager;

    @Override
    public String resolveThemeName( HttpServletRequest request )
    {
        String theme = profileManager.getUserTheme();
        if ( theme == null )
        {
            theme = getDefaultThemeName();
        }
        return theme;
    }

    @Override
    public void setThemeName( HttpServletRequest request, HttpServletResponse response, String themeName )
    {
        if ( themeName != null )
        {
            profileManager.saveUserTheme( themeName );
        }
    }

}
